import threading

import time

piao = 100
#互斥锁由于阻止了多线程并发，效率降低了
suo = threading.Lock()
def maipiao():
    global piao
    global suo
    while True:
        #加锁
        suo.acquire()
        if piao >0:
            print(threading.current_thread().name + '卖票：'+str(piao))
            piao = piao -1
            time.sleep(0.1)
        #解锁
        suo.release()
if __name__ =='__main__':
    ck1 = threading.Thread(name='窗口1',target=maipiao)
    ck1.start()

    ck2 = threading.Thread(name='窗口2', target=maipiao)
    ck2.start()